import { BaseDrawInfo, BaseLineInfo } from "..";
import { drawerAop } from "../drawer-aop";

interface ArcDrawInfo extends BaseDrawInfo, BaseLineInfo {
  // 圆心 x 位置
  x: number;
  // 圆心 y 位置
  y: number;
  // 圆半径
  radius: number;
  // 开始弧度
  startAngle?: number;
  // 结束弧度
  endAngle?: number;
  // 是否为逆时针
  counterclockwise?: boolean;
  // 是否闭合
  close?: boolean;
}

export class ArcHelper {
  static getInstance() {
    return new ArcHelper();
  }

  private constructor() {}

  @drawerAop({ dealStrokeFill: true })
  draw(ctx: CanvasRenderingContext2D, drawInfo: ArcDrawInfo) {
    const { x, y, radius, counterclockwise, close } = drawInfo;
    const startAngle = drawInfo.startAngle ?? 0;
    const endAngle = drawInfo.endAngle ?? 2 * Math.PI;
    ctx.arc(x, y, radius, startAngle, endAngle, counterclockwise);
    if (close) ctx.closePath();
  }
}

export const arc = ArcHelper.getInstance();
